/**
 * 滑动窗口。本题要求的子数组为连续取数
 * @param {number} target
 * @param {number[]} nums
 * @return {number}
 */
var minSubArrayLen = function (target, nums) {
    let nLen = nums.length,
        left = 0,
        right = 0,
        tempSum = 0,
        res = 1000000

    while (right < nLen) {
        tempSum += nums[right]
        while (tempSum >= target) {
            res = (right - left + 1) > res ? res : (right - left + 1)
            tempSum -= nums[left]
            left++
        }
        right++
    }

    return res === 1000000 ? 0 : res
};

console.log(minSubArrayLen(7, [2, 3, 1, 2, 4, 3]))